/*******************************************************************
*
*    DESCRIPTION:
*
*    AUTHOR:
*
*    HISTORY:
*
*    DATE:8/31/2006
*
*******************************************************************/
#include "eggtrayicon.h"
#include "trayicon.h"
#include "head.h"
#include "config.h"
/*
 *Function Name:
 *
 *Parameters:
 *
 *Description:
 *
 *Returns:
 *
 */
gboolean tray_button_press_event_cb (GtkWidget *button, GdkEventButton *event, GtkMenu *menu)
{
#ifdef _DEBUG
	printf("Enter tray_button_press_event\nEventtype is %d\n",event->button);
#endif
	GtkWidget *main_window = glade_xml_get_widget(gui_xml, "dialog_main");
	g_return_val_if_fail ((event->type == GDK_BUTTON_PRESS), FALSE); /* ignore double-click or any others */
#ifdef _DBUG
	printf("The mouse key is:%d\n", event->button);
#endif
	switch ( event->button )
	{
		case MIDDLE_BUTTON:
			break;

		case RIGHT_BUTTON:
			/* popup menu */
			gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, event->button, event->time);
			break;

		default:
			return FALSE;
	}

	return TRUE;
}

/*
 *Function Name:load_image
 *
 *Parameters:
 *
 *Description:
 *
 *Returns:
 *
 */

GtkWidget *load_image (const gchar *filename)
{
	GtkWidget *image;
	GdkPixbuf *pixbuf;

	pixbuf = gdk_pixbuf_new_from_file (filename, NULL);
	if ( !pixbuf )
	{
		image = gtk_image_new_from_stock (GTK_STOCK_HOME, GTK_ICON_SIZE_MENU);
	}
	else
	{
		image = gtk_image_new_from_pixbuf (pixbuf);
	}

	return image;
}

/*
 *Function Name:create_tray
 *
 *Parameters:
 *
 *Description:
 *
 *Returns:
 *
 */
void CreateTray(GtkWidget *menu)
{
	GtkWidget *image;
	GtkWidget *event_box;
	GtkTooltips *tooltips;
	EggTrayIcon *tray_icon;

	tooltips = gtk_tooltips_new ();
	tray_icon = egg_tray_icon_new ("coolnet firewall");
	event_box = gtk_event_box_new ();
	gtk_container_add (GTK_CONTAINER (tray_icon), event_box);
	g_signal_connect (G_OBJECT (event_box), "button-press-event",
					  G_CALLBACK (tray_button_press_event_cb), menu);
	gtk_tooltips_set_tip (GTK_TOOLTIPS(tooltips), event_box, "coolnet firewall", NULL);

	image = load_image (COOLNET_ICON);
	gtk_container_add (GTK_CONTAINER (event_box), image);

	gtk_widget_show_all (GTK_WIDGET (tray_icon));

	return;
}
